package com.goods.controller.business;

import com.goods.business.service.ISupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 *
 * @Date: 2023/3/6 - 14:30
 * @Author: Hyoung
 * @Description:
 */
@RestController
@RequestMapping("/business/supplier")
public class SuppilerController {
    // ?pageNum=1&pageSize=10&name=fdas&address=fa&contact=fasd

    @Autowired
    private ISupplierService iSupplierService;

    /**
     * 分页带条件查询
     *
     * @param pageNum
     * @param pageSize
     * @param supplierVO
     * @return findSupplierList
     */
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize") Integer pageSize,
                                         SupplierVO supplierVO) {
        PageVO<SupplierVO> supplierPageVO = iSupplierService.findSupplierList(pageNum, pageSize, supplierVO);
        return ResponseBean.success(supplierPageVO);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Integer id) {
        iSupplierService.deleteSupplierById(id);
        return ResponseBean.success();
    }

    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO) {
        iSupplierService.addSupplier(supplierVO);
        return ResponseBean.success();
    }

    @GetMapping("/edit/{id}")
    public ResponseBean editSupplier(@PathVariable Integer id) {
        SupplierVO supplierVO = iSupplierService.findSupplierById(id);
        return ResponseBean.success(supplierVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateSupplier(@PathVariable Integer id, @RequestBody SupplierVO supplierVO) {
        iSupplierService.updateSupplier(id, supplierVO);
        return ResponseBean.success();
    }

    //business/supplier/findAll
    @GetMapping("/findAll")
    public ResponseBean findAll() {
        List<SupplierVO> supplierVOList = iSupplierService.findAll();
        return ResponseBean.success(supplierVOList);
    }
}
